package com.test.springai.service;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 8/22/25 3:44 PM
 * @modifiedBy:
 * @version: 1.0
 */
public class StockFunctionService
    implements Function<StockFunctionService.Request, StockFunctionService.Response> {
  private static final Logger LOGGER = LoggerFactory.getLogger(StockFunctionService.class);

  /**
   * 通过账号account和密钥key获取个人股票账户信息
   *
   * @param account
   * @param key
   */
  @JsonClassDescription("通过账号account和密钥key获取个人股票账户信息")
  public record Request(@JsonProperty("account") String account, @JsonProperty("key") String key) {}

  /**
   * 返回个人帐户的股票名称name、股票代码code、股票价格price、股票数量value
   *
   * @param name
   * @param code
   * @param price
   * @param value
   */
  @JsonClassDescription("股票账户查询响应,返回个人帐户的股票名称name、股票代码code、股票价格price、股票数量value")
  public record Response(
      @JsonProperty("name") String name,
      @JsonProperty("code") String code,
      @JsonProperty("price") String price,
      @JsonProperty("value") String value) {}

  /**
   * 应用函数：根据请求获取股票账户信息
   *
   * @param request the request
   * @return the response
   */
  @Override
  public Response apply(Request request) {
    // TODO 调用券商API实现账号account和密钥key获取个人股票账户信息，这里直接模拟数据进行返回
    LOGGER.info("接收到查询请求，账号: {}, 密钥: {}", request.account(), request.key());
    // 模拟实际API调用和数据返回
    return new Response("电力", "600000", "10.00", "1000");
  }
}
